<template>

  <div class="shop" v-loading='loading'>
    <!-- <el-button size='small' class="addResidence"
        type='primary'
        @click="addResidenceAudit">新增入驻商户</el-button> -->
    <el-form ref="filtrateForm" :inline="true" size="mini" :model="form" class="form">
      <!-- <el-form-item label="所属区域:">
        <el-select
          style="width:130px;"
          v-model="province"
          filterable
          placeholder="省份"
          @change="onChangeProvince"
        >
          <el-option
            v-for="item in provinceList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
        <el-select
          style="width:130px;"
          v-model="city"
          filterable
          placeholder="市"
          @change="onChangeCity"
        >
          <el-option v-for="item in cityList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <el-select style="width:130px;" v-model="area" filterable placeholder="区">
          <el-option
            v-for="item in areaList"
            :key="item.id"
            :label="item.name"
            :value="item.areaCode"
          ></el-option>
        </el-select>
      </el-form-item> -->

      <!-- <el-form-item label = "账号状态:">
          <el-select style="width:130px;" v-model="form.status" filterable placeholder="全部" >
             <el-option v-for="item in statusList" :key="item.id" :label="item.status" :value="item.id"></el-option>
          </el-select>
      </el-form-item>-->

      <el-form-item label="商家分类:">
        <el-select style="width:130px;" v-model="form.type_id" filterable placeholder="全部">
          <el-option v-for="item in statusList" :key="item.id" :label="item.title" :value="item.id"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="入驻类型:">
        <el-select style="width:130px;" v-model="form.pay_type" filterable placeholder="全部">
          <el-option label="全部" value="3"></el-option>
          <el-option label="小店" value="0"></el-option>
          <el-option label="年费会员店" value="1"></el-option>
          <el-option label="押金会员店" value="2"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否会员店:">
        <el-select style="width:130px;" v-model="form.is_vip_shop" filterable placeholder="全部">
          <el-option v-for="item in isMemberList" :key="item.id" :label="item.title" :value="item.id"></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="小店分组:">
        <el-select style="width:130px;" v-model="form.group_id" filterable placeholder="全部">
          <el-option v-for="item in groupList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item> -->

      <!-- <el-form-item label="上架商品:">
        <el-select style="width:130px;" v-model="form.is_up_goods" filterable placeholder="全部">
          <el-option
            v-for="item in upgoodslist"
            :key="item.id"
            :label="item.status"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item> -->


      <!-- <el-form-item label = "上架活动:">
          <el-select style="width:130px;" v-model="form.is_up_activity" filterable placeholder="全部">
             <el-option v-for="item in isActivityList" :key="item.id" :label="item.title" :value="item.id"></el-option>
          </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="上架优惠券:">
        <el-select style="width:130px;" v-model="form.is_up_coupon" filterable placeholder="全部">
          <el-option
            v-for="item in upcouponlist"
            :key="item.id"
            :label="item.status"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item style="float:right;">
        <el-button type="primary" @click="searchShop">搜索</el-button>
      </el-form-item>
      <el-form-item style="float:right;">
        <el-input v-model="form.keywords" placeholder="输入小店名或ID搜索"></el-input>
      </el-form-item>



    </el-form>

    <el-table :data="tableData" style="width:100%" height="680" :cell-style="tc" :header-cell-style="tccolor">

      <el-table-column prop="uid" label="UID">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" :value="true" :manual="true" content="退费犹豫期" placement="top-end"
            v-if="scope.row.vip_shop_delete_status == 1">
            <p style="text-align:bottom">{{ scope.row.uid }}</p>
          </el-tooltip>
          <p v-else>{{ scope.row.uid }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="shop_name" label="小店名称" width='160'></el-table-column>
      <el-table-column prop="memberMobile" label="小店账号" width="140"></el-table-column>
      <el-table-column label="门店地址" width="160">
        <template slot-scope="scope">{{ scope.row.province }} {{ scope.row.city }} {{ scope.row.area }}</template>
      </el-table-column>
      <!-- <el-table-column prop="status" label="主账号状态" width="120">
        <template slot-scope="scope">
          <el-switch
            :key="scope.row.id"
            :active-value="1"
            :inactive-value="0"
            :value="scope.row.status"
            @change="isUseActivityChange(scope.row.id,$event)"
          ></el-switch>
        </template>
      </el-table-column>-->
      <el-table-column label="商家分类" width="140">
        <template slot-scope="scope">
          <p v-if="scope.row.title">{{ scope.row.title }}</p>
          <p v-else>---</p>
          <!-- <strong

            @click="changeCategoryName(scope.row)"
            class="lookbig"
          >(修改分类)</strong> -->
        </template>
      </el-table-column>
      <el-table-column label="入驻类型" width='140'>
        <template slot-scope="scope">
          <p v-if="scope.row.vip_shop_pay_type == 0">小店</p>
          <p v-if="scope.row.vip_shop_pay_type == 1">年费会员店</p>
          <p v-if="scope.row.vip_shop_pay_type == 2">押金会员店</p>
        </template>
      </el-table-column>
      <el-table-column label="服务费扣点" width='140'>
        <template slot-scope="scope">
          <p v-if="scope.row.vip_shop_pay_type == 0">小店</p>
          <p v-if="scope.row.vip_shop_pay_type == 1">年费会员店</p>
          <p v-if="scope.row.vip_shop_pay_type == 2">押金会员店</p>
        </template>
      </el-table-column>
      <el-table-column label="服务经理" width='140'>
        <template slot-scope="scope">
          <p v-if="scope.row.vip_shop_pay_type == 0">小店</p>
          <p v-if="scope.row.vip_shop_pay_type == 1">年费会员店</p>
          <p v-if="scope.row.vip_shop_pay_type == 2">押金会员店</p>
        </template>
      </el-table-column>
      <!-- <el-table-column  label="小店分组">
        <template slot-scope="scope">
           <p v-if='scope.row.union_name'>{{scope.row.union_name}}</p>
           <p v-else>---</p>
        </template>
      </el-table-column> -->

      <!-- <el-table-column  label="是否会员店" width='100'>
        <template slot-scope="scope">
           <p >{{scope.row.is_vip_shop_word}}</p>
           <p v-else>否</p>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="上架商品">
        <template slot-scope="scope">
          <p v-if="scope.row.c_id ||  scope.row.s_id">是</p>
          <p v-else>否</p>
          <p>{{scope.row.is_up_good_word}}</p>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="isActivity" label="上架活动" >
        <template slot-scope="scope">
          <p >{{scope.row. is_up_activity_word}}</p>
          <p v-else>否</p>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="isCoupon" label="上架优惠券" width='100'>
        <template slot-scope="scope">
          <p v-if="scope.row.c_id ||  scope.row.s_id">是</p>
          <p v-else>否</p>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="可用收益">
        <template slot-scope="scope">
          {{scope.row.account_balance}} <span style="color:#f4222d;cursor:pointer;" @click="lookAccountBalance(scope.row.id)">(查看)</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="小店粉丝数" width="140">
        <template slot-scope="scope">
          <p class="shop_cate" v-if="scope.row.title">{{scope.row.title}}</p>
          <p  class="shop_cate" v-else>---</p>
          <strong

            @click="changeCategoryName(scope.row)"
            class="lookbig"
          >(查看)</strong>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="小店会员数" width="140">
        <template slot-scope="scope">
          <p class="shop_cate" v-if="scope.row.title">{{scope.row.title}}</p>
          <p  class="shop_cate" v-else>---</p>
          <strong

            @click="changeCategoryName(scope.row)"
            class="lookbig"
          >(查看)</strong>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" fixed="right" width="340">
        <template slot-scope="scope">
          <!-- <el-button size="mini"  @click="openShopDetail(scope.row.id)">详情</el-button> -->
          <el-button size="mini" @click="watchDetail(scope.row.id)">入驻信息</el-button>
          <el-button size="mini" @click="goShopMember">查看会员</el-button>
          <!-- <el-button size="mini"  @click="gotoShowOrder(scope.row.id)">查看订单</el-button>
            <el-button size="mini" type="primary" @click="showPurseRecordList(scope.row.id)">红包充值记录</el-button> -->
          <!-- <el-button size="mini" type="primary" @click="bindCardMemberShop(scope.row)">绑定卡号段</el-button> -->

          <!-- <el-button size="mini" type="primary" v-if="scope.row.vip_shop_delete_status == 1"  @click="remokeremoveShop(scope.row.id)">撤销</el-button>
          <el-button size="mini"  type="primary" v-else @click="DeleteCardMemberShop(scope.row.id,scope.row.is_vip_shop_word,scope.row.create_time,scope.row.vip_shop_pay_type,scope.row.initial_money_yuan)">移除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <el-col :span="24">
      <div class="pagination">
        <el-pagination background @size-change="handleSizeChange" @current-change="pageChange" :current-page="form.page"
          :page-size="form.size" layout="total, prev, pager, next, jumper" :total="total"></el-pagination>
      </div>
    </el-col>

    <jdialog title="修改分类" :visible.sync="dialogVisible" width="800px">
      <el-radio-group v-model="shocategoryData.type_id" class="radio_select_group">
        <el-radio class="radio_select" v-for="item in statusList" :key="item.id" border :label="item.id">{{ item.title
          }}</el-radio>
      </el-radio-group>
      <div class="class_btn">
        <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="certainChangeCategory">确 定</el-button>
      </div>
      <span slot="footer" class="dialog-footer"></span>
    </jdialog>

    <!--绑定卡号段-->
    <el-dialog title="绑定商户卡号段" :visible.sync="isAddMemberCard" center>
      <el-row>
        <el-col :span="4">
          <el-button size="mini" type="primary" @click="selectShopSeller">选择绑定商家</el-button>
        </el-col>
        <el-col :span="20">
          <div v-if="selectShopDetail.name" class="bind_shop">已绑定：{{ selectShopDetail.name }}</div>
        </el-col>
      </el-row>
      <el-row class="bind_card_row">
        <el-col :span="8">
          <div v-if="redpacketAmount > 0" class="bind_shop">{{ redpacketAmount }}</div>
          <div v-else class="bind_shop">返显红包总额</div>
        </el-col>
        <el-col :span="8">
          <div v-if="cardNumberAmount > 0" class="bind_shop">{{ cardNumberAmount }}</div>
          <div v-else class="bind_shop">返显分号段总数</div>
        </el-col>
        <el-col :span="8">
          <div v-if="bindCardAmount > 0" class="bind_shop">{{ bindCardAmount }}</div>
          <div v-else class="bind_shop">返显绑卡总数总额</div>
        </el-col>
      </el-row>
      <el-row class="bind_card_row" v-for="(item, index) of AddCardList" :key="index">
        <el-col :span="24">
          <div class="member_order">{{ item.num }}</div>
          <i v-if="index > 0" class="el-icon-close delete_shoplist" @click="deleteMemberlistdata(index)"></i>
        </el-col>
        <el-col :span="18">
          <el-input style="width:42%;" v-model="item.start" placeholder="起始卡号段" clearable></el-input>------
          <el-input style="width:42%;" v-model="item.end" placeholder="末尾卡号段" clearable></el-input>
        </el-col>
        <el-col :span="6">
          <el-input v-model="item.price" placeholder="输入红包配额" clearable @blur="getCardNumber"></el-input>
        </el-col>
      </el-row>
      <el-row>
        <div class="add_shop" @click="addShopGroupFormlist">+ 添加分号段</div>
      </el-row>

      <el-dialog title="选择绑定商家" :visible.sync="isShowSelectShop" center append-to-body>
        <el-form>
          <p>提示：选择商家时系统将为您过滤已参与其他联盟且仍在有效期中的商户</p>
          <el-row>
            <el-col :span="12">
              <el-input v-model="keywords" placeholder="输入商家名称搜索" clearable></el-input>
            </el-col>
            <el-button class="select_btn_shop" type="primary" @click="searchvouchlist">搜索</el-button>
          </el-row>
          <el-table :data="selectShopdata" border highlight-current-row @current-change="handleCurrentChange"
            :cell-style="tc" :header-cell-style="tccolor">
            <el-table-column prop="name" label="商户名称"></el-table-column>
            <el-table-column prop="address" label="地址信息"></el-table-column>
            <el-table-column prop="username" label="联系人"></el-table-column>
            <el-table-column prop="tel" label="联系方式"></el-table-column>
          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="isShowSelectShop = false">取 消</el-button>
          <el-button type="primary" @click="selectShopInfo">保存</el-button>
        </div>
      </el-dialog>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelMemberCard">取 消</el-button>
        <el-button type="primary" @click="submitMemberCardInfo">确 定</el-button>
      </div>
    </el-dialog>

    <!--充值小店红包金额-->
    <jdialog title="充值红包" :visible.sync='isShowRechargePurse' width='600px;'>
      <div style="padding:20px;">
        <p style="margin-bottom:12px;color:#333;">提示：红包充值成功后，小店账号中对应增加充值金额，已充值红包不可回收</p>

        <span style="color:red;">*</span><span style="margin-right:8px;">充值金额:</span><el-input placeholder="输入红包充值金额"
          v-model="rechargeAmount" type='number' min="0" style="width:450px;"></el-input><span
          style="margin-left:8px;">元</span>

        <div style="text-align:center;margin-top:12px;">
          <el-button size="mini" @click="cancelRechargePurse">取消</el-button>
          <el-button size="mini" type="primary" @click="certainRechargePurse">确定</el-button>
        </div>
      </div>

    </jdialog>

    <!--移除、强制移除-->
    <jdialog title="请选择移除类型" :visible.sync='isDeleteType' width='600px;'>
      <div style="padding:20px; text-align:center;">
        <div class="del_left">
          <i class="el-icon-delete-solid" style="cursor:pointer" @click="forceAndRefundDel"></i>
          <p @click="forceAndRefundDel" style="cursor:pointer">强制移除</p>
        </div>
        <div class="del_right">
          <i class="el-icon-s-tools" style="cursor:pointer" @click="refundDelete"></i>
          <p @click="refundDelete" style="cursor:pointer">退款移除</p>
        </div>
      </div>
    </jdialog>
    <jdialog title="强制移除确认" :visible.sync='isForeceDel' width='600px;'>
      <div style="padding:20px;">
        <i class="el-icon-warning-outline" style="color:orange; font-size:24px;"></i> <span
          style="margin-left:8px;font-size:15px;">强制移除确认</span>
        <p style="padding:20px 0;font-size:14px;">此操作后，小店关联的邀请关系和上下级粉丝关系将会被移除，小店身份变为乐粉，是否继续操作?</p>
        <div style="text-align:center;margin:0 0 12px 0;">
          <el-button size="mini" @click="isForeceDel = false">取消</el-button>
          <el-button size="mini" type="primary" @click="certainForeceDelAndRefunc">确认</el-button>
        </div>
      </div>
    </jdialog>
    <jdialog title="退款移除确认" :visible.sync='isRefundDel' width='600px;'>
      <div style="padding:20px;">
        <i class="el-icon-warning-outline" style="color:orange; font-size:24px;"></i> <span
          style="margin-left:8px;font-size:15px;">退费移除确认</span>
        <p style='padding:10px 0;'>当前可退费比例:<span>100%</span></p>
        <p style='padding:0 0 16px 0;'>退费移除后，会员店身份被回收，变为小店，通过系统退费.</p>

        <span>退费金额:</span><el-input style="width:160px;margin:0 12px;" size="small"
          v-model="refund_money"></el-input><span>元</span>
        <div style="text-align:center;margin:12px 0 12px 0;">
          <el-button size="mini" @click="isRefundDel = false">取消</el-button>
          <el-button size="mini" type="primary" @click="certainRefunc">确认</el-button>
        </div>
      </div>
    </jdialog>

    <!--押金小店退款移除确认-->
    <jdialog title="退款移除确认" :visible.sync='isYajin' width='600px;'>
      <div style="padding:20px;">
        <i class="el-icon-warning-outline" style="color:orange; font-size:24px;"></i> <span
          style="margin-left:8px;font-size:15px;">当前小店为押金入驻小店</span>
        <p style='padding:10px 0;'>可退费押金:<span>{{ refund_money_all }}元</span></p>
        <p style='padding:0 0 16px 0;'>退费移除后，会员店身份被回收，变为小店，通过系统退费.</p>
        <!-- <br/> -->
        <span>退费金额:</span><el-input style="width:160px;margin:0 12px;" size="small"
          v-model="refund_money"></el-input><span>元</span>
        <div style="text-align:center;margin:12px 0 12px 0;">
          <el-button size="mini" @click="isYajin = false">取消</el-button>
          <el-button size="mini" type="primary" @click="certainYajinRefunc">确认</el-button>
        </div>
      </div>
    </jdialog>

    <jdialog title="撤销移除确认" :visible.sync='isRevokeDel'>
      <div style="padding:20px;">
        <i class="el-icon-warning-outline" style="color:orange; font-size:24px;"></i> <span
          style="margin-left:8px;font-size:15px;">撤销移除确认</span>
        <p style='padding:0 0 16px 0;margin-top:20px;'>撤销移除后，小店将恢复会员店身份，请与小店确认是否撤销?</p>
        <div style="text-align:center;margin:0 0 12px 0;">
          <el-button size="mini" @click="isRevokeDel = false">取消</el-button>
          <el-button size="mini" type="primary" @click="certainRevokeRefunc">确认</el-button>
        </div>
      </div>
    </jdialog>

    <jdialog title="红包充值记录" :visible.sync="isShowPurseRecord" width="640px">

      <div class="recordPurse">
        <p>合计充值笔数: {{ totalRecharge }}</p>
        <p>合计充值金额: ¥{{ totalRechargeAmount }}</p>
        <p>当前红包余额: ¥{{ currentPurseAmount }}</p>
      </div>
      <el-table :data="rechargeTableData" style="width:100%" class="bindcardrecord" max-height="600" :cell-style="tc"
        :header-cell-style="tccolor">
        <el-table-column label="日期" prop="create_time"></el-table-column>
        <el-table-column label="充值红包金额">
          <template slot-scope="scope">¥{{ scope.row.money_tlj }}</template>
        </el-table-column>
        <el-table-column label="充值来源">
          <template slot-scope="scope">
            <p v-if="scope.row.source_from == 55">后台充值</p>
            <p v-if="scope.row.source_from == 30">红包充值</p>
          </template>
        </el-table-column>
        <!-- <el-table-column label="支付金额">
            <template slot-scope="scope">
              <p v-if="scope.row.order">¥ {{scope.row.order.actual_amount}}</p>
              <p v-else>---</p>
            </template>
          </el-table-column> -->
      </el-table>

      <el-col :span="24">
        <div class="pagination">
          <el-pagination background @current-change="RechargepageChange" :current-page="rechargeForm.page"
            :page-size="10" layout="total, prev, pager, next, jumper" :total="rechargeTotal"></el-pagination>
        </div>
      </el-col>
    </jdialog>

    <!--查看订单类型-->
    <jdialog title="请选择查看订单类型" :visible.sync="showOrderType" width="420px">
      <el-row class="orders">
        <el-col :span="12">
          <el-button class="goodsorder" type="primary" icon="el-icon-tickets" circle
            @click="gotoGoodsOrder"></el-button>
          <p>淘客CPS订单</p>
        </el-col>

        <el-col :span="12">
          <el-button class="cashsorder" type="success" icon="el-icon-bank-card" circle
            @click="gotoCashsOrder"></el-button>
          <p class>红包兑换订单</p>
        </el-col>
      </el-row>
    </jdialog>
  </div>
</template>

<script>
import {
  provinceCityArea,
  shopTypeList,
  shopGroupList,
  shopList,
  shopTypeIdModify,
  shopSellerSelect,
  shopCardTljRecharge,
  shopWithShopIdRemove,
  revokeRemoveShop
} from "@/api/goods";
import { cardXiBind } from "@/api/member";
import { cardShopIdRechargeSearch } from "@/api/shopdetail";
// import store from "@/store";
export default {
  data() {
    return {
      loading: true,
      dialogVisible: false,
      shocategoryData: { type_id: "", shop_id: "" },
      province: "",
      city: "",
      area: "",
      total: 0,
      form: {
        type_id: 0,
        //   status: "",
        group_id: "",
        is_up_goods: "",
        //   activity: "",
        is_up_coupon: "",
        keywords: "",
        city_area: "",
        adcode: "",
        is_up_cash_coupon: "",
        is_vip_shop: '',
        is_up_activity: '',
        page: 1,
        size: 20,
        pay_type: ''
      },

      provinceList: [],
      cityList: [],
      areaList: [],
      statusList: [],
      groupList: [],
      upcouponlist: [{ id: 1, status: "是" }, { id: 0, status: "否" }],
      upgoodslist: [{ id: 1, status: "是" }, { id: 0, status: "否" }],
      isMemberList: [{ id: 1, title: "是" }, { id: 0, title: "否" }],
      isActivityList: [{ id: 1, title: "是" }, { id: 0, title: "否" }],
      tableData: [],

      //绑定卡号段相关
      isAddMemberCard: false,
      isShowSelectShop: false,
      //商户分类列表
      selectShopdata: [],
      keywords: "",
      AddCardList: [],
      selectShopDetail: {},
      //红包总额
      redpacketAmount: 0,
      //分号段总数
      cardNumberAmount: 0,
      //返显绑卡数总额
      bindCardAmount: 0,


      //充值红包
      isShowRechargePurse: false,
      rechargeAmount: '',
      currentRechargeId: '',

      //强制移除
      isDeleteType: false,
      deleteShopId: '',
      delType: '',
      delIsVip: '',
      isForeceDel: false,
      current_time: '',

      //退款移除
      isRefundDel: false,
      isRevokeDel: false,

      pay_type: '',
      refund_money: '',
      refund_money_all: '',
      isYajin: false,
      refund_money_quankuan: '',

      //充值红包来源
      isShowPurseRecord: false,
      totalRecharge: 0,
      totalRechargeAmount: 0,
      currentPurseAmount: 0,
      rechargeTableData: [],
      rechargeTotal: 0,
      rechargeForm: {
        page: 1,
        size: 10
      },
      showOrderType: false,
      showOrderId: ''
    };
  },
  mounted() {
    console.log(this)
  },
  created() {
    // this.getProvinceDataList("1", "0");
    // this.getShopList();
    // this.getShopGroupList();
    this.form.type_id = this.$route.query.cid;
    if (!this.form.type_id) {
      this.form.type_id = "";
    }
    this.getShopListData();
  },
  // beforeRouteEnter(to,from,next){
  //    next(vm =>{
  //       vm.getProvinceDataList("1", "0");
  //   vm.getShopList();
  //   vm.getShopGroupList();
  //   vm.form.type_id = this.$route.query.cid;
  //   if (!vm.form.type_id) {
  //     vm.form.type_id = "";
  //   }
  //   vm.getShopListData();
  //    })
  // },

  methods: {
    onChangeProvince(e) {
      //切换省,同时获取省对应的城市 e是城市对应的id

      this.province = e;
      //后面加获取对应省的城市接口
      this.city = "";
      this.area = "";
      this.getProvinceDataList("2", e);
    },
    onChangeCity(e) {
      this.city = e;
      this.area = "";
      //获取对应城市的区
      this.getProvinceDataList("3", e);
    },
    changeCategoryName(data) {
      this.shocategoryData = { shop_id: data.id, type_id: data.type_id };
      this.dialogVisible = true;
    },
    certainChangeCategory() {
      this.getcertainChangeCategoryData();
    },
    async getcertainChangeCategoryData() {
      let res = await shopTypeIdModify(this.shocategoryData);
      if (res.code === 10000) {
        this.$message.success("修改成功");
        this.dialogVisible = false;
        this.getShopListData();
      } else {
        this.$message.error(res.message);
      }
    },
    //搜索对应小店
    searchShop() {
      this.getShopListData();
    },
    tc() {
      return "text-align:center; color:#333333; font-size:12px;";
    },
    tccolor() {
      return "text-align:center;background-color:#f5f5f5; font-size:14px;";
    },
    //获取省列表
    async getProvinceDataList(t, p) {
      let res = await provinceCityArea({ type: t, pid: p });

      if (res.code === 10000) {
        if (t === "1") {
          this.provinceList = res.data;
        } else if (t === "2") {
          this.cityList = res.data;
        } else {
          this.areaList = res.data;
        }
      }
    },
    handleSizeChange(val) {
      this.form.size = val;
      this.pageChange(1);
    },
    pageChange(page) {
      this.form.page = page;
      this.getShopListData();
    },
    //获取小店列表
    async getShopListData() {
      if (
        (this.province && !this.city) ||
        (this.province && !this.area && !this.city)
      ) {
        this.$message.error("市或区不能为空");
        return;
      }
      if (this.area) {
        this.form.city_area = 3;
        this.form.adcode = this.area;
      } else if (this.city) {
        this.form.city_area = 2;
        this.form.adcode = this.city;
      } else {
        this.form.city_area = 0;
        this.form.adcode = "";
      }
      if (this.form.pay_type == 3) {
        this.form.pay_type = ''
      }
      let res = await shopList(this.form);
      if (res.code === 10000) {
        this.loading = false
        this.tableData = res.data.data;
        this.total = res.data.total;
      } else {
        this.loading = false
      }

    },
    async getShopList() {
      let res = await shopTypeList({ keywords: "", page: 1, size: 40 });

      this.statusList = res.data.data;
    },

    //获取小店分组列表
    async getShopGroupList() {
      let res = await shopGroupList({
        keywords: "",
        province_id: "",
        city_id: "",
        region_id: ""
      });
      console.log(res.data.data)
      this.groupList = res.data.data;
    },
    //查看会员
    goShopMember() {
      this.$router.push({ path: 'shopMember' })
    },
    //打开小店详情
    openShopDetail(id) {
      //   router.push({path:'/'})
      //跳转小店详情
      // store.dispatch("setDetail", data);
      this.$router.push({ path: "./shoplistDetail", query: { shopid: id } });
    },
    lookAccountBalance(id) {
      this.$router.push({ path: "./shoplistDetail", query: { shopid: id, activeName: 'nineth' } });
    },
    bindCardMemberShop(val) {
      this.selectShopDetail = { id: val.id, name: val.shop_name };
      this.AddCardList = [{ num: 1, start: "", end: "", price: "" }];
      this.redpacketAmount = this.bindCardAmount = this.cardNumberAmount = 0;
      this.isAddMemberCard = true;
    },
    //移除小店
    DeleteCardMemberShop(id, isVip, time, type, money) {

      this.deleteShopId = id
      this.delIsVip = isVip
      this.current_time = time
      this.pay_type = type
      if (type == 1 || type == 2) {
        this.isDeleteType = true
        this.refund_money_all = money
      } else {
        //普通小店直接强制移除
        this.isForeceDel = true
      }
    },
    //确认押金退款
    certainYajinRefunc() {
      this.getshopWithShopIdRemoveData()
    },
    bindMemmberBtnClick() {
      (this.selectShopDetail = {}),
        (this.AddCardList = [{ num: 1, start: "", end: "", price: "" }]);
      this.redpacketAmount = this.bindCardAmount = this.cardNumberAmount = 0;
      this.isAddMemberCard = true;
    },
    //绑定商户卡号段
    submitMemberCardInfo() {
      if (this.selectShopDetail) {
        for (var i = 0; i < this.AddCardList.length; i++) {
          var form = {
            shop_id: this.selectShopDetail.id,
            price: this.AddCardList[i].price,
            start: this.AddCardList[i].start,
            end: this.AddCardList[i].end
          };
          this.getCardXiBindData(form, i);
        }
      } else {
        this.$message.error("必须选择一个商家绑定");
      }
    },
    //添加卡号段
    async getCardXiBindData(form, index) {
      let res = await cardXiBind(form);
      if (index === this.AddCardList.length - 1 && res.code === 10000) {
        this.$message.success("绑定卡号段成功");
        this.isAddMemberCard = false;
      } else if (index === this.AddCardList.length - 1 && res.code !== 10000) {
        this.$message.error(res.message);
      }
    },
    cancelMemberCard() {
      this.isAddMemberCard = false;
      this.selectShopDetail = {};
    },
    selectShopSeller() {
      this.isShowSelectShop = true;
      this.getshopSellerSelectList();
    },
    //获取商户列表
    async getshopSellerSelectList() {
      let res = await shopSellerSelect({ keywords: this.keywords });
      this.selectShopdata = res.data.data;
    },
    searchvouchlist() {
      this.getshopSellerSelectList();
    },

    //选择商户
    selectShopInfo() {
      if (this.selectShopDetail) {
        this.isShowSelectShop = false;
      } else {
        this.$message.error("请选择一个商家");
      }
    },
    handleCurrentChange(val) {
      this.selectShopDetail = val;
    },

    //添加商户
    addShopGroupFormlist() {
      if (this.AddCardList.length === 2) {
        this.$message.error("最多添加2个");
        return;
      } else {
        this.AddCardList.push({ num: 2, start: "", end: "", price: "" });
      }
    },

    //删除商户
    deleteMemberlistdata(index) {
      if (this.AddCardList.length === 1) {
        this.$message.error("最少一个");
      } else {
        this.AddCardList.splice(index, 1);
        this.getCardNumber();
      }
    },

    //计算红包总额、号码段总数等、
    getCardNumber() {
      this.redpacketAmount = this.cardNumberAmount = this.bindCardAmount = 0;
      for (var i = 0; i < this.AddCardList.length; i++) {
        var form = this.AddCardList[i];
        if (form.start > 0 && form.end > 0 && form.price > 0) {
          this.redpacketAmount =
            this.redpacketAmount + (form.end - form.start + 1) * form.price;
          this.cardNumberAmount = i + 1;
          this.bindCardAmount = this.bindCardAmount + form.end - form.start + 1;
        }
      }
    },

    //充值小店红包金额
    rechargeShopRedpacket(id) {
      this.currentRechargeId = id
      this.isShowRechargePurse = true
    },

    //确定充值
    certainRechargePurse() {
      if (Number(this.rechargeAmount) <= 0) {
        this.$message.error('充值金额不能小于0')
        return
      } else {
        this.getshopCardTljRechargeData(this.currentRechargeId)
      }
    },

    //取消充值
    cancelRechargePurse() {
      this.isShowRechargePurse = false
      this.rechargeAmount = ''
    },
    //充值小店红包金额
    async getshopCardTljRechargeData(id) {
      let res = await shopCardTljRecharge({ shop_id: id, red_packed_price: this.rechargeAmount })
      if (res.code === 10000) {
        this.$message.success(res.message)
        this.isShowRechargePurse = false
        this.rechargeAmount = ''
        //刷新小店数据
        this.getShopListData()
      } else {
        this.$message.error(res.error)
      }
    },
    //强制移除
    forceAndRefundDel() {
      this.isForeceDel = true
      this.delType = 1
    },
    //退费退款移除
    refundDelete() {
      this.delType = 2
      console.log(this.pay_type)
      if (this.pay_type == 1) {
        this.isRefundDel = true
        // this.isYajin = true
      } else {
        this.isYajin = true
      }
    },
    //强制确认、退款确认
    certainForeceDelAndRefunc() {
      this.delType = 1
      this.getshopWithShopIdRemoveData()
    },
    //退款移除确认
    certainRefunc() {
      if (this.delIsVip !== '是') {
        this.$message.error('非会员店不能退费移除')
        return;
      }
      var time_diff = new Date().getTime() - new Date(this.current_time).getTime();
      // 计算相差天数
      var days = Math.floor(time_diff / (24 * 3600 * 1000));
      if (days > 15) {
        this.$message.error('超过15天不能退费移除')
        return;
      }

      this.getshopWithShopIdRemoveData()
    },
    //小店移除
    async getshopWithShopIdRemoveData() {
      console.log(this.delType)
      var form = {}
      if (this.delType == 1) {
        form = {
          type: this.delType
        }
      } else {

        if (Number(this.refund_money) <= 0 && this.delType == 2) {
          this.$message.error('退费金额不能为小于0')
          return;
        }
        form = { type: this.delType, refund_money: this.refund_money }
      }
      let res = await shopWithShopIdRemove(this.deleteShopId, form)
      if (res.code === 10000) {
        this.refund_money = ''
        this.$message.success(res.message)
        this.getShopListData()
        if (this.delType == 1) {
          this.isForeceDel = false
        } else {
          if (this.pay_type == 1) {
            this.isRefundDel = false

          } else {
            this.isYajin = false
          }
        }
        this.isDeleteType = false
      } else {
        this.$message.error(res.message)
      }
    },
    remokeremoveShop(id) {
      this.deleteShopId = id
      this.isRevokeDel = true
    },
    certainRevokeRefunc() {
      this.getrevokeRemoveShopData()
    },
    //撤销移除
    async getrevokeRemoveShopData() {
      let res = await revokeRemoveShop(this.deleteShopId)
      if (res.code === 10000) {
        //  if(res.data == 'true'){
        this.$message.success(res.message)
        this.getShopListData()
        this.isRevokeDel = false
        //  }else{
        //  this.$message.error(res.error)
        //  }
      } else {
        this.$message.error(res.message)
      }
    },

    //新增入驻商户
    addResidenceAudit() {
      this.$router.push({
        path: "../management/residenceinformation",
        query: { type: 2 }
      });
    },

    //完善入驻信息
    watchDetail(id) {
      this.$router.push({
        path: "./residenceinformation",
        query: { cid: id, type: 2, isWatchOrEdit: false }
      });
    },

    //充值记录相关
    RechargepageChange(page) {
      this.rechargeForm = page;
      // this.getshopBindCardData(this.shopId)
    },
    showPurseRecordList(id) {
      this.getcardShopIdRechargeSearchData(id)
    },
    async getcardShopIdRechargeSearchData(id) {
      let res = await cardShopIdRechargeSearch(id)
      if (res.code === 10000) {
        this.isShowPurseRecord = true
        this.rechargeTableData = res.data.card_records_page.data
        this.rechargeTotal = res.data.card_records_page.total
        this.totalRecharge = res.data.card_records_page.total
        this.totalRechargeAmount = res.data.sum_tlj
        this.currentPurseAmount = res.data.balance_tlj
      } else {
        this.$message.error(res.message)
      }
    },
    gotoShowOrder(id) {
      this.showOrderId = id
      this.showOrderType = true
    },
    //淘客cps订单
    gotoGoodsOrder() {
      this.showOrderType = false;
      this.$router.push({
        path: "/taokeCPSOrderProfit",
        query: { shop_id: this.shopId }
      });
    },
    //红包兑换订单
    gotoCashsOrder() {
      this.showOrderType = false;
      this.$router.push({
        path: "/hbExchangeProfit",
        query: { shop_id: this.shopId }
      });
    },

  }
};
</script>

<style lang="scss" scoped>
.shop {
  padding: 20px;
  position: relative;

  .addResidence {
    position: absolute;
    top: 0;
    right: 0;
  }

  .lookbig {
    font-weight: 400;
    color: #f4222d;
    cursor: pointer;
  }

  .radio_select_group {
    margin-top: 20px;
    padding: 15px;
  }

  .radio_select {
    margin-bottom: 15px;
    margin-left: 15px;
  }

  .shop_cate {
    float: left;
  }

  .add_shop {
    text-align: center;
    border: 1px solid #a8a8a8;
    line-height: 30px;
    font-size: 13px;
    cursor: pointer;
  }

  .pagination {
    float: right;
    margin-top: 10px;
  }

  .class_btn {
    margin-top: 20px;
    margin-bottom: 20px;
    text-align: center;
  }

  .bindcardrecord {
    padding: 15px 20px;
  }

  //绑定卡号段相关
  .bind_shop {
    color: #a8a8a8;
    border: 1px solid #e5e5e5;
    // padding: 10px;
    height: 27px;
    line-height: 27px;
    text-align: center;
    margin-left: 10px;
  }

  .bind_card_row {
    border: 1px dashed #a8a8a8;
    margin: 20px 0;
    padding: 24px 20px;
    position: relative;
  }

  .delete_shoplist {
    float: right;
    background-color: #f4222d;
    color: white;
    position: absolute;
    right: 0;
    top: 0;
  }

  .member_order {
    float: left;
    color: #ffffff;
    background-color: #f4222d;
    font-size: 14px;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    margin-right: 10px;
    position: absolute;
    left: 0;
    top: 0;
  }

  .del_left,
  .del_right {
    text-align: center;
    float: left;
    width: 50%;

    i {
      font-size: 48px;
      color: #999999;
    }

    p {
      margin: 10px 0 20px 0;
      color: #666666;
      font-size: 14px;
    }
  }

  .recordPurse {
    margin: 20px 20px;
    border: 1px solid #999999;
    height: 48px;

    p {
      float: left;
      width: 180px;
      margin-top: 12px;
      line-height: 24px;
      height: 24px;
      text-align: center;
    }
  }

  .goodsorder {
    // float: right;
    width: 50px;
    height: 50px;
    margin-bottom: 16px;
  }

  .cashsorder {
    // float: left;
    width: 50px;
    height: 50px;
    margin-bottom: 16px;
  }

  .orders {
    margin: 36px 0px;
    text-align: center;
  }

}
</style>
